-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug Fix] Grouping Cluster Resources by group and Kind #875
Conversation
@@ -238,9 +238,10 @@ def secrets_from_ejson | |||
def discover_resources | |||
@logger.info("Discovering resources:") | |||
resources = [] | |||
crds_by_kind = cluster_resource_discoverer.crds.group_by(&:kind) | |||
crds_by_group_kind = cluster_resource_discoverer.crds.group_by(&:group_kind) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there tests to cover this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will be great to test this change, this is supposed to change the order of the items
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added new tests to cover these changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is supposed to change the order of the items
I don't quite understand what you mean by this, could you explain please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, sorry, I misread the issue in #873 and I thought a consequence of this PR is that it'll change the order of the items in some list, however, this change is about grouping differently. Sorry for the noise
it seems some tests are broken:
|
lib/krane/deploy_task.rb
Outdated
@template_sets.with_resource_definitions(current_sha: @current_sha, bindings: @bindings) do |r_def| | ||
crd = crds_by_kind[r_def["kind"]]&.first | ||
grouping, version = r_def.dig("apiVersion").split("/") | ||
group = version ? grouping : "core" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does mean "core" in this context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When extracting group
, lib/krane/kubernetes_resource.rb
returns the group defined in the resource definition or core
. We need to do something similar here for r_def
but we cannot use the same method in lib/krane/kubernetes_resource.rb
so I decided to replicate the behaviour here instead (hence the core
).
@@ -238,9 +238,10 @@ def secrets_from_ejson | |||
def discover_resources | |||
@logger.info("Discovering resources:") | |||
resources = [] | |||
crds_by_kind = cluster_resource_discoverer.crds.group_by(&:kind) | |||
crds_by_group_kind = cluster_resource_discoverer.crds.group_by(&:group_kind) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is supposed to change the order of the items
I don't quite understand what you mean by this, could you explain please?
@@ -59,7 +59,7 @@ def status | |||
end | |||
|
|||
def type | |||
kind | |||
group_kind |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For other reviewers:
#type
is already a somewhat overloaded method. In particular, KubernetesResource#type
has as body:
def type
@type || self.class.kind
end
#type
is mainly used internally, most critically in DeployTask#deploy_has_priority_resources?
, though it's value also appears in the tool's output.
#type
is also aliased to KubernetesResource#kubectl_resource_type
, which is used by ResourceCache
. There is already a case where #type
is overridden to include the group suffix.
All this to say, I'm hoping the use of group_kind
here isn't too controversial :)
def group_kind | ||
"#{kind}.#{group}" | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The behaviour of CustomResourceDefinition#kind and #group
is a little strange (you might expect it to return CRD
and apiextensions
, respectively), but since this is previous behaviour I think it's ok to leverage it
definition: { "kind" => "UnitTest", "metadata" => { "name" => "test" } }) | ||
definition: { | ||
"kind" => "UnitTest", | ||
"apiVersion" => "stable.example.io/v1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to add apiVersion
to make these tests pass (since we now parse group info). Since all k8s objects require this field, it makes sense to add it instead of accommodating its absence
@@ -450,7 +487,7 @@ def test_deploying_crs_with_invalid_crd_conditions_fails | |||
end | |||
end | |||
assert_deploy_failure(result) | |||
prefixed_name = add_unique_prefix_for_test("Customized-with-customized-params") | |||
prefixed_name = add_unique_prefix_for_test('Customized.stable.example.io-with-customized-params').to_s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the most visible consequence of our change, and I would argue it's a feature: CRDs are now logged showing both their group and kind. This should make things easier to understand in the case of multiple kinds among difference groups
You'll also need to fix the CR logic in |
There seems to be a different issue in |
Closing as stale |
What are you trying to accomplish with this PR?
Fixes #873
How is this accomplished?
Instead of grouping by
kind
inDeployTask#discover_resources
, we now group bygroup
andkind
to avoid picking the wrong CRD when there are duplicates of the samekind
.What could go wrong?
...